<template>
	<div>
		<Row :gutter="16">
			<ICol span="3" >
				<router-link to="/wechat/function/reply/update"><Button type="primary">添加回复</Button></router-link>
			</ICol>
			<ICol span="6">
				<IInput v-model="params.search"   placeholder="搜索关键词/规则名" clearable />
			</ICol>
			<ICol span="6">
				<Button type="primary" @click="search">搜索</Button>
			</ICol>
		</Row>
		<BaseTable ref="table" :url="table.url" :header="table.header" :async="false" ></BaseTable>
	</div>
</template>
<script>
	import {Row,Col,Button,Input} from 'view-design';

	import BaseTable  from 'admin/components/common/table/base'

	export default {
		components:{
        	Row,
            'ICol':Col,
            Button,
            'IInput' : Input,
            BaseTable,
        },
        data () {
            return {
            	table:{
            		url : '/wechat/function/reply/view/list',
            		header: []
            	},
            	params:{
            		search: '',
            	}
            }
        },
        methods:{
        	init(name){
        		this.$refs.table.tableData();
        	},
        	search(){
        		this.$refs.table.tableData(this.params);
        	}
        },
        created:function(){
        	this.table.header =  [
                {
			        title: '规则名',
			        key: 'ruleName'
			    },
			    {
			        title: '关键词',
			        key: 'keyword'
			    },
			    {
			        title: '回复类型',
			        key: 'replyType',
			        render:(h,params)=>{
			        	switch(params.row.replyType){
			        		case 'mpnews':
			        		return '图文消息';
			        		case 'text':
			        		return '文本消息';
			        		case 'image' :
			        		return '图片消息';
			        	}
			        }
			    },
			    {
			        title: '操作',
			        key: 'action',
			        width: 150,
			        align: 'center',
			        render: (h, params) => {
			            return h('div', [
			                h(Button, {
			                    props: {
			                        type: 'primary',
			                        size: 'small'
			                    },
			                    style: {
			                        marginRight: '5px'
			                    },
			                    on: {
			                        click: () => {
			                        	this.$router.push('/wechat/function/reply/update/'+params.row.id);
			                        }
			                    }
			                }, '编辑'),
			                h(Button, {
			                    props: {
			                        type: 'error',
			                        size: 'small'
			                    },
			                    on: {
			                        click: () => {
			                        	this.$Modal.confirm({
						                    title: '删除确定',
						                    content : '你确定要删除吗？删除后无法恢复',
						                    loading: true,
						                    onOk: () => {
						                        this.Axios.Wechat.Function.Reply.Del(params.row.id)
						                        .then(res =>{
						                            if(!res) return false;
						                            this.$Modal.remove();
						                            this.$refs['table'].tableData();
						                        })
						                    }
						                });
			                        }
			                    }
			                }, '删除')
			            ]);
			        }
			    }
            ];
        }
	}
</script>